<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0;">
      <el-form :inline="true" :model="filters" ref="filters">
        <el-form-item label="姓名">
          <el-input v-model="filters.name" placeholder="请输入姓名" size="small"></el-input>
        </el-form-item>
        <el-form-item label="章节名称" prop="type">
          <el-select v-model="filters.type" placeholder="请选择"
                     style="width: 680px"
          >
            <el-option
              v-for="item in types"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getTableData" icon="el-icon-search" size="small">搜素</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="resetForm('filters')" icon="el-icon-refresh" size="small">重置</el-button>
        </el-form-item>
      </el-form>
      <!--      修改-->
      <div>
        <el-button type="primary" size="small" icon="el-icon-plus" @click="add">新增</el-button>
        <el-button type="success" size="small" icon="el-icon-edit">修改</el-button>
        <el-button type="danger" size="small" icon="el-icon-delete">删除</el-button>
        <el-button type="warning" size="small" icon="el-icon-download">导出</el-button>
      </div>

      <!--列表-->
      <el-table :data="tableData"
                style="width: 100%;"
      >
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index" width="60">
        </el-table-column>
        <el-table-column prop="name" label="学生姓名" sortable>
        </el-table-column>
        <el-table-column prop="wechat" label="学生微信">
        </el-table-column>
        <el-table-column prop="phone" label="学生电话">
        </el-table-column>
        <el-table-column prop="squad" label="班级">
        </el-table-column>
        <el-table-column prop="time" label="预约时间">
        </el-table-column>
        <el-table-column prop="teacher" label="帮扶老师">
        </el-table-column>
        <el-table-column prop="issue" label="问题类型">
          <template slot-scope="scope">
            <el-tag disable-transitions>
              {{ scope.row.issue }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state===1" disable-transitions>
              待处理
            </el-tag>
            <el-tag v-else-if="scope.row.state===2" disable-transitions>
              成功解决
            </el-tag>
            <el-tag v-else-if="scope.row.state===3" disable-transitions>
              处理失败
            </el-tag>
            <el-tag v-else disable-transitions>
              移交他⼈
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="depicted" label="问题描述">
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template scope="scope">
            <el-button size="small" @click="edit(scope.row)" icon="el-icon-edit" type="primary">编辑</el-button>
            <el-button type="danger" size="small" @click="del( scope.row)" icon="el-icon-close">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>

    <el-col :span="24" class="toolbar">
      <el-pagination layout="prev, pager, next" @current-change="selectPage" :page-size="pageSize" :total="total"
                     style="float:right;"
      >
      </el-pagination>
    </el-col>
    <common ref="Common"></common>

  </section>
</template>

<script>
import { getList } from '@/api/teacher/teacher'
import {getLists,getdalete } from '@/api/teacher/student'
import { deyList, labelList } from '@/api/teacher/Label'
import Common from '../../components/Helping/common'

export default {
  name: 'helping',
  data() {
    return {
      addFormVisible: false,
      addLoading: false,
      static: false,
      // 条件
      filters: {
        type: '',
        name: ''
      },
      deyList: [],
      teachers: [],
      tableData: [],
      types: [],
      label: [],
      addForm: {
        id: '',
        name: '',
        wechat: '',
        phone: '',
        squad: '',
        time: '',
        teacher: '',
        issue: '',
        state: '',
        depicted: ''
      },
      addFormRules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '请输入电话', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '请输入性别', trigger: 'blur' }
        ]
      }

    }
  },
  methods: {
    del: function(row) {
      getdalete(row.id).then(response => {
        if (response) {
          this.$message({ message: '删除成功', type: 'success' })
          this.list()
        } else {
          this.$message({ message: '删除失败', type: 'success' })
        }
      }).cache(error => {
        this.$message({ message: '数据加载失败[' + error.message + ']', type: 'error' })
      })

    },
    selectPage(val) {
      this.page = val
      this.getTableData()
    },
    add() {
      this.$refs.Common.add()
    },
    getFileName(files) {
      return files.slice(0, 3)
    },
    list() {
      getLists().then(response => {
        this.tableData = response.data
      }).catch(reason => {
        console.log(reason)
      })
    },
    type() {
      getType().then(response => {
        console.log(response.data)
        this.types = response.data
      }).catch(reason => {
        console.log(reason)
      })
    },
    edit(row) {
      this.$refs.Common.edit(row)
    },
    labelList() {
      labelList().then(response => {
        this.label = response.data
      }).cache(reason => {
        this.$message({ message: '数据加载失败[' + error.message + ']', type: 'error' })
      })
    },

    // 获取老师
    getList() {
      getList().then(response => {
        this.teachers = response.data
        this.labelList()
      }).cache(reason => {
          this.$message({ message: '数据加载失败[' + error.message + ']', type: 'error' })
        }
      )
    },
    // 问题
    getdeyList() {

      deyList().then(response => {
        this.deyList = response.data
        this.getList()
      }).cache(response => {
        this.$message({ message: '数据加载失败[' + error.message + ']', type: 'error' })
      })

    }
  },
  components: { Common },
  mounted() {
    this.getdeyList()
  },
  created() {
    this.list()
  }

}
</script>

